/*     */ package com.newcrm.db;
/*     */ 
/*     */ import com.newcrm.config.Config;
/*     */ import com.newcrm.exception.DBException;
/*     */ import java.sql.Connection;
/*     */ import java.sql.SQLException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.apache.commons.dbutils.DbUtils;
/*     */ import org.apache.commons.dbutils.GenKeyQueryRunner;
/*     */ import org.apache.commons.dbutils.MyMapListHandler;
/*     */ import org.apache.commons.dbutils.QueryRunner;
/*     */ import org.apache.commons.dbutils.handlers.ScalarHandler;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class TaskCategoryManager
/*     */ {
/*  23 */   private static Logger logger = Logger.getLogger(NoteManager.class.getName());
/*     */ 
/*     */   public List<Map<String, Object>> list(int companyId)
/*     */     throws DBException, SQLException
/*     */   {
/*  35 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  36 */     if (conn == null) {
/*  37 */       throw new DBException();
/*     */     }
/*     */ 
/*  40 */     QueryRunner runner = new QueryRunner();
/*     */     try {
/*  42 */       return (List)runner.query(conn, "SELECT TaskCategoryId,TaskCategoryName,Color FROM T_Task_Category_Info WHERE CompanyId = ? ORDER BY OrderNum ASC ", 
/*  43 */         new MyMapListHandler(), new Object[] { Integer.valueOf(companyId) });
/*     */     } finally {
/*     */       try {
/*  46 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/*  48 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   public int add(int companyId, String name, String userId)
/*     */     throws DBException, SQLException
/*     */   {
/*  65 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  66 */     if (conn == null) {
/*  67 */       throw new DBException();
/*     */     }
/*  69 */     GenKeyQueryRunner runner = new GenKeyQueryRunner(
/*  70 */       new ScalarHandler(), new String[] { "TaskCategoryId" });
/*     */     try {
/*  72 */       runner.update(conn, "INSERT INTO T_Task_Category_Info (TaskCategoryName, CompanyId, CreateDate, CreateUserId) VALUES (?, ?, NOW(), ?)", new Object[] { name, Integer.valueOf(companyId), 
/*  73 */         userId });
/*  74 */       return ((Long)runner.getGeneratedKeys()).intValue();
/*     */     } finally {
/*     */       try {
/*  77 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/*  79 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   public int update(int id, String name, String color, String userId)
/*     */     throws DBException, SQLException
/*     */   {
/*  97 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  98 */     if (conn == null) {
/*  99 */       throw new DBException();
/*     */     }
/* 101 */     QueryRunner runner = new QueryRunner();
/*     */     try
/*     */     {
/*     */       int i;
/* 104 */       if ((name == null) || (name.trim().length() == 0)) {
/* 105 */         return runner.update(conn, "UPDATE T_Task_Category_Info SET Color = ?, UpdateDate = NOW(), UpdateUserId = ? WHERE TaskCategoryId = ?", new Object[] { 
/* 106 */           color, userId, Integer.valueOf(id) });
/*     */       }
/* 108 */       return runner.update(conn, "UPDATE T_Task_Category_Info SET TaskCategoryName = ?, Color = ?, UpdateDate = NOW(), UpdateUserId = ? WHERE TaskCategoryId = ?", new Object[] { name, 
/* 109 */         color, userId, Integer.valueOf(id) });
/*     */     } finally {
/*     */       try {
/* 112 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/* 114 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   public int delete(int customerFieldId)
/*     */     throws DBException, SQLException
/*     */   {
/* 128 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 129 */     if (conn == null) {
/* 130 */       throw new DBException();
/*     */     }
/* 132 */     QueryRunner runner = new QueryRunner();
/*     */     try
/*     */     {
/* 135 */       int result = runner.update(conn, "DELETE FROM T_Task_Category_Info WHERE TaskCategoryId = ?", 
/* 136 */         Integer.valueOf(customerFieldId));
/* 137 */       return result;
/*     */     } finally {
/*     */       try {
/* 140 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/* 142 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   public void init(int companyId, String userId)
/*     */     throws DBException, SQLException
/*     */   {
/* 157 */     Config config = Config.getInstance();
/* 158 */     String taskCategorys = config.taskCategory;
/*     */ 
/* 160 */     if ((taskCategorys == null) || (taskCategorys.trim().length() == 0)) {
/* 161 */       return;
/*     */     }
/*     */ 
/* 164 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 165 */     if (conn == null) {
/* 166 */       throw new DBException();
/*     */     }
/* 168 */     QueryRunner runner = new QueryRunner();
/*     */ 
/* 170 */     String[] arrCate = taskCategorys.split(",");
/*     */     try {
/* 172 */       List baseParams = new ArrayList();
/* 173 */       for (String cate : arrCate)
/* 174 */         if ((cate != null) && (cate.trim().length() != 0))
/*     */         {
/* 177 */           List info = new ArrayList();
/* 178 */           info.add(cate);
/* 179 */           info.add(Integer.valueOf(companyId));
/* 180 */           info.add(userId);
/* 181 */           baseParams.add(info.toArray(new Object[0]));
/*     */         }
/* 183 */       runner.batch(conn, "INSERT INTO T_Task_Category_Info (TaskCategoryName, CompanyId, CreateDate, CreateUserId) VALUES (?, ?, NOW(), ?)", 
/* 184 */         (Object[][])baseParams.toArray(new Object[0][]));
/*     */     } finally {
/*     */       try {
/* 187 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/* 189 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   public int updateSort(int id, int order, String userId)
/*     */   {
/* 203 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 204 */     if (conn == null) {
/* 205 */       return 0;
/*     */     }
/* 207 */     QueryRunner runner = new QueryRunner();
/*     */     try
/*     */     {
/* 210 */       return runner.update(conn, "UPDATE T_Task_Category_Info SET OrderNum = ? , UpdateDate = NOW(), UpdateUserId = ? WHERE TaskCategoryId = ?", new Object[] { 
/* 211 */         Integer.valueOf(order), userId, Integer.valueOf(id) });
/*     */     } catch (SQLException e) {
/* 213 */       logger.warn("update order failed", e);
/*     */     } finally {
/*     */       try {
/* 216 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/* 218 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/* 221 */     return 0;
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.db.TaskCategoryManager
 * JD-Core Version:    0.6.1
 */